﻿Chenxin.UI.DepartmentListManageer = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: 'service/DepartmentList.ashx',
    createGrid: function() {
        // return new Chenxin.UI.Pagination({
        // actionUrl: this.actionUrl + '?op=show',
        // renderTo: 'setting_table'
        // });

        return new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            renderTo: 'setting_table',
            title: '部门列表',
            height: 300,
            modelId: 'DepartId',
            hasCheckBox: false,
            columns: {
                DepartCode: {
                    head: '部门编号',
                    width: 80
                },
                DepartName: {
                    head: '部门名称',
                    width: 80
                },
                City: {
                    head: '城市',
                    width: 60
                },
                CompanyName: {
                    head: '所属公司',
                    width: 90
                },
                DepartKind: {
                    head: '类别',
                    width: 80
                },
                Tel: {
                    head: '电话',
                    width: 100
                },
                Address: {
                    head: '地址'
                },
                Email: {
                    head: 'Email',
                    width: 100
                },
                IsOpen: {
                    head: '开通',
                    width: 30,
                    renderer: function(val) {
                        if (val) {
                            return '是';
                        }
                        return '否'
                    }
                },
                IsCalculate: {
                    head: '统计',
                    width: 30,
                    renderer: function(val) {
                        if (val) {
                            return '是';
                        }
                        return '否'
                    }
                },
                Region: {
                    head: '区域',
                    width: 60
                },
                Bussiness: {
                    head: '商圈',
                    width: 90
                }
            },
            scope: this
        });
    },
    initEvent: function() {
        var _this = this;
        // $('.tr_houselist').live('click', function() {
        // $('.tr_houselist,.selected_orgbgcolor').each(function() {
        // $(this).removeClass('selected_orgbgcolor');
        // });
        // $(this).toggleClass('selected_orgbgcolor');
        // $("#hidSelected").val(this.id);
        // });
        // $('.tr_houselist').live('mouseover', function() {
        // $(this).toggleClass('orgbgcolor');
        // });
        // $('.tr_houselist').live('mouseout', function() {
        // $(this).toggleClass('orgbgcolor');
        // });

        $("#aDepSettingEdit").live("click", function() {
            _this.showDepSettingEdit();
        });
    },
    /**
    *部门参数编辑
    */
    showDepSettingEdit: function() {
        var _this = this;

        //被选择的行
        if (!this.currentId) {
            alert("请选择一行后进行编辑");
            return;
        }
        // if ($("#hidSelected").val() == "") {
        // alert("请选择一行后进行编辑");
        // return;
        // }

        if (!this.jqmDepSetting) {
            this.jqmDepSetting = new Chenxin.UI.DepSettingEditForm({
                scope: this,
                jqmHeight: 360,
                customerFormVal: function(model) {
                    if (this.needArea && !this.additionalParam.Area) {
                        alert('必须选择片区！');
                        return false;
                    }
                    return true;
                },
                afterGetFormJson: function(json) {
                    //json.DepartId = $("#hidSelected").val();
                    json.DepartId = this.currentId;
                    Chenxin.apply(this.jqmDepSetting.additionalParam, json);
                    /*
                    if (json.IsOpen != undefined)
                    this.jqmDepSetting.additionalParam.IsOpen = json.IsOpen;
                    if (json.IsCalculate != undefined)
                    this.jqmDepSetting.additionalParam.IsCalculate = json.IsCalculate;
                    if (json.IsContractCenter != undefined)
                    this.jqmDepSetting.additionalParam.IsContractCenter = json.IsContractCenter;
                    if (json.IsRoof != undefined)
                    this.jqmDepSetting.additionalParam.IsRoof = json.IsRoof;
                    if (json.RegionCtr != undefined)
                    this.jqmDepSetting.additionalParam.RegionCtr = json.RegionCtr
                    delete json.IsOpen;
                    delete json.IsCalculate;
                    delete json.IsContractCenter;
                    delete json.IsRoof;
                    delete json.RegionCtr;
                    delete json.Area;
                    */

                }
            });
        }

        if (this.jqmDepSetting.show('edit')) {
            this.jqmDepSetting.tab.activeTab(0);
            Chenxin.ajax({
                type: "get",
                dataType: "json",
                url: 'service/DepartmentList.ashx',
                data: { op: "GetSettingInfo", DepId: this.currentId }, //DepId: $("#hidSelected").val() 
                onSuccess: function(data) {
                    _this.jqmDepSetting.fitData(data.setting);
                    // _this.jqmDepSetting.cmbregionCtr.param.cityid = data.CityId;
                    // _this.jqmDepSetting.cmbregionCtr.param.filter = 'bycity';
                    // _this.jqmDepSetting.cmbregionCtr.reload(data.RegionCtr);

                    var ras = _this.jqmDepSetting.findByName('rasetting');
                    ras.baseParam.cityid = data.CityId;
                    ras.reload();

                    $('#ctr_region_' + _this.jqmDepSetting.id).text(data.RegionCtr);
                    $('#ctr_area_' + _this.jqmDepSetting.id).text(data.Area);


                    _this.jqmDepSetting.findByName('rasetting').text = { RegionCtr: data.RegionCtr, Area: data.Area };
                    _this.jqmDepSetting.needArea = data.needArea;

                    $("#div_canaddcity h6").text(data.setting.CanAddAtCityName);
                    if (data.IsOpen == 'True')
                        _this.jqmDepSetting.findByName('IsOpen').attr("checked", true);
                    if (data.IsCalculate == 'True')
                        _this.jqmDepSetting.findByName('IsCalculate').attr("checked", true);
                    if (data.IsContractCenter == 'True')
                        _this.jqmDepSetting.findByName('IsContractCenter').attr("checked", true);
                    if (data.IsRoof == 'True')
                        _this.jqmDepSetting.findByName('IsRoof').attr("checked", true);
                }
            });
        }
    },
    createSearch: function() {
        return new Chenxin.UI.DepartmentListSearch({
            scope: this
        });
    },
    initComponent: function() {
        Chenxin.UI.DepartmentListManageer.superclass.initComponent.call(this);
    }
});


/**
*查询面板
*/
Chenxin.UI.DepartmentListSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'departmentlist_search',
    initEvent: function() {
        var _this = this;
        $('#btn_search').click(function() {
            _this.scope.reloadGrid();
        });
    },
    createComboList: function() {
        var combl = new Chenxin.UI.StructComboList({tbxWidth:60});
        var structs = combl.comboList;
        var optDepartKind = new Chenxin.UI.Combo({
            containerId: '#divType',
            items: [{ txt: '总部', val: '1' },
                                             { txt: '直营店', val: '2' },
                                             { txt: '加盟店', val: '3'}],
            tbxWidth: 80,
            inModelType: 'txt'
        });

        structs.push(optDepartKind);
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.DepartmentListSearch.superclass.initComponent.call(this);
    }
});


/**
*部门参数修改
*/
Chenxin.UI.DepSettingEditForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/DepartmentList.ashx',
    id: 'jqmDepSetting',
    renderTo: 'divjqmDepSetting',
    title: '部门参数编辑',
	op:'edit',
	defBBtn:true,
    jqmWidth: 700,
    //    initFormValidator: function() {
    //    var _this = this;
    //        
    //    },
    createForm: function() {
		return Chenxin.FormCommon.departSetting(this.id);
        //return formCommon.DepSetting();
    },
    initEvent: function() {
        // var _this = this;
        // 提交按钮事件
        // $('#aSubmitDepart').live('click', function() {
            // _this.op = 'edit';
            // _this.save();
        // });
        // 关闭按钮事件
        // $('#aCloseDepart').live('click', function() {
            // _this.hide();
        // });<tr><td colspan="4"><div style="float:right; margin-right:15px;"><input type="button" id="aSubmitDepart" class="btn_n_2 fl" value="提交" /><a id="aCloseDepart" class="btn_n fl" ><span>关闭</span></a></div></td></tr>
    },
//    reloadRegionCtr: function(cityid) {
//        cmbregionCtr = this.findByName('RegionCtr');
//        cmbregionCtr.param.cityid = cityid;
//        cmbregionCtr.param.filter = 'bycity';
//        debugger;
//        cmbregionCtr.reload();
//    },
    createComboList: function() {
        var _this = this;
        //可添加房源的城市
        this.cmbcity = new Chenxin.UI.Combo({
            actionUrl: 'service/structhandler.ashx',
            param: { op: 'getcity' },
            tbxWidth: 150,
            typeModel: 'new',
            containerId: '#div_canaddcity',
            showMode: 'multi',
            inModelType: 'all',
            name: 'CanAddAtCityId',
            txtModelName: 'CanAddAtCityName',
            required: true,
            autoLoad: true,
            typeModel: 'new',
            colNum: 5
        });
		var ra=new Chenxin.UI.RegionAreaWinCombo({
			containerId:'a_rsra_'+this.id,
			inModelName:{Area:'level_2',RegionCtr:'level_1'},
			type:'btncombo',
			name:'rasetting',
			autoLoad:false,
			displayDom:{level_1:$('#ctr_region_'+this.id),level_2:$('#ctr_area_'+this.id)}
			//displayDom:[$('#ctr_region_'+this.id),$('#ctr_area_'+this.id)]
		});
        // this.cmbregionCtr = new Chenxin.UI.ParameterCombo({
            // name: 'RegionCtr',
            // containerId: '#RegionCtr',
            // key: 'System.Region',
            // showMode: 'multi',
            // colNum: 3,
            // inModelType: 'txt',
            // autoLoad: false,
            // tbxWidth: 200
        // });
        // return [this.cmbcity, this.cmbregionCtr];
		return [this.cmbcity,ra];
    },
    initComponent: function() {
        Chenxin.UI.DepSettingEditForm.superclass.initComponent.call(this);
		this.tab=new Chenxin.UI.Tab({
			id:'tab_'+this.id
		});
    }
});
Chenxin.FormCommon.departSetting=function(id){
	return '<div id="tab_'+id+'"><ul><li>基本设定</li><li>管理设定</li></ul><div><div><table class="tbl_f"><tr class="tdheight"><td colspan="2" style="margin-right: 5px;"><span class="magsidlf">是否开通：</span><input type="checkbox" value="true" name="IsOpen" />是</td><td colspan="2" style="margin-right: 5px;"><span class="magsidlf">计算业绩：</span><input type="checkbox" value="true" name="IsCalculate" />是</td></tr><tr class="tdheight"><td colspan="2" style="margin-right: 5px;"><span class="magsidlf">签约中心：</span><input type="checkbox" value="true" name="IsContractCenter" />是</td><td colspan="2" style="margin-right: 5px;"><span class="magsidlf">商圈平台：</span><input type="checkbox" value="true" name="IsRoof" />是</td></tr><tr><td colspan="4"><hr /></td></tr><tr class="tdheight"><td colspan="2"><span class="magsidlf">每天查看电话数量限制</span><input type="text" id="txtOwnerNum" name="ViewOwnerNum" style="width: 50px;" />(次)&nbsp;&nbsp; </td><td width="337" colspan="2" ><span class="magsidlf">封盘最长有效期</span><input type="text" id="txtLockHouseDay" name="LockHouseDay" style="width: 50px;" />(天)</td></tr><tr  class="tdheight"><td colspan="2"><span class="magsidlf">手动保护房源设定</span><input type="text" id="txtProtectedNum" name="ProtectedNum" style="width: 50px;" />(套)&nbsp;&nbsp;</td><td colspan="2"><span class="magsidlf">保护时限</span><input type="text" id="txtMarkProtectHours" name="MarkProtectHours" style="width: 50px;" />(小时)</td></tr><tr class="tdheight"><td colspan="2"><span class="magsidlf">需求客户数量上限</span><input type="text" id="txtCustomerDemandNum" name="CustomerDemandNum" style="width: 50px;" />(个)(0为不限)&nbsp;&nbsp; </td><td colspan="2"><span class="magsidlf">超时未客户/客需跟单上限</span><input type="text" id="txtOverTimeTraceNum" name="OverTimeTraceNum" style="width: 50px;" />(天)(0为不限)</td></tr><tr class="tdheight"><td colspan="4"><div class="magsidlf fl"><span class="isfilled">*</span>可添加房源的所在城市：</div><div id="div_canaddcity" class="SelectWrapSingle fl" name="CanAddAtCityId"  style="z-index:400;margin-right: 5px;"></div></td></tr><tr class="tdheight"><td colspan="4"><div class="magsidlf"><span class="spanwh138"><input type="checkbox" id="cbxHdeHouse" name="IsHideHouse" value="true" /> 房源是否隐藏</span><span class="spanwh138"><input type="checkbox" id="cbxIsProtectMark" name="IsProtectMark" value="true"/>备案进行保护</span><span class="spanwh138"><input type="checkbox" id="cbxAllowPrivHouse" name="AllowPrivHouse" value="true"/>允许输入私盘  </span><span class="spanwh138"><input type="checkbox" id="cbxAllowPrivDemand" name="AllowPubDemand" value="true"/>允许输入公需</span></div></td></tr><tr><td colspan="4"><div class="magsidlf"><span class="spanwh138"><input type="checkbox" id="cbxIsUseBlacklist" name="IsUseBlacklist" value="true"/>使用黑名单过滤 </span><span class="spanwh150"><input type="checkbox" id="cbxIsTelRepeat" name="IsTelRepeat" value="true"/>入客需，电话号码重复性检查  </span></div></td></tr><tr class="tdheight"><td colspan="4"><div class="magsidlf">黑名单级别：<input type="radio" id="rdoCompany" name="BlacklistLevel" value="10" checked="checked" />10:公司级；<input type="radio" id="rdoDePart" name="BlacklistLevel" value="20" />20:部门级；<input type="radio" id="rdoPerson" name="BlacklistLevel" value="30" />30:个人级；</div></td></tr></table></div><div><table class="tbl_f"><tr><th style="width:100px;">管理区域：</th><td><span id="ctr_region_'+id+'"></span></td><td rowspan="2" style="vertical-align:top;width:50px;"><a id="a_rsra_'+id+'" class="x-button fr" ><span>重新设定</span></a></td></tr><tr><th style="width:100px;">管理片区：</th><td><span id="ctr_area_'+id+'"></span></td></tr></table></div></div>';
}

$(document).ready(function() {
    var favorMgr = new Chenxin.UI.DepartmentListManageer();
});





